﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Traceability_2203.Common.DBcontexts;
using Traceability_2203.Common.Infrastructure.interFaces;

namespace Traceability_2203.Common.Infrastructure.Repostories
{
    public class BaseRepository<T> : IBaseRepository<T> where T : class, new()
    {

        /// <summary>
        /// 上下文
        /// </summary>
        EFDBcontexts db;

        public BaseRepository(EFDBcontexts db)
        {
            this.db = db;
        }



        /// <summary>
        /// 获取所有的数据
        /// </summary>
        /// <returns>获取所有的数据</returns>
        public async Task<IQueryable<T>> GetAll()
        {
            return db.Set<T>().AsQueryable();
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public async  Task<int> Add(T t)
        {
            
            db.Set<T>().Add(t);
            return await db.SaveChangesAsync();

        }

   
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public async Task<int> update(T t)
        {
           db.Set<T>().Update(t);
            return await db.SaveChangesAsync();
        }
    }
}
